abstract class ContextLoaderUtils
extends java.lang.Object
ContextLoaders
and
SmartContextLoaders
and resolving resource locations,
configuration classes, and active bean definition profiles.ContextLoader
,
SmartContextLoader
,
ContextConfiguration
,
ContextConfigurationAttributes
,
ActiveProfiles
,
MergedContextConfiguration
Modifier and Type | Field and Description |
---|---|
private static java.lang.String |
DEFAULT_CONTEXT_LOADER_CLASS_NAME |
private static Log |
logger |
Modifier | Constructor and Description |
---|---|
private |
ContextLoaderUtils() |
Modifier and Type | Method and Description |
---|---|
(package private) static MergedContextConfiguration |
buildMergedContextConfiguration(java.lang.Class<?> testClass,
java.lang.String defaultContextLoaderClassName)
Build the
merged context configuration
for the supplied testClass and
defaultContextLoaderClassName . |
(package private) static java.lang.String[] |
resolveActiveProfiles(java.lang.Class<?> clazz)
Resolve active bean definition profiles for the supplied
Class . |
(package private) static java.util.List<ContextConfigurationAttributes> |
resolveContextConfigurationAttributes(java.lang.Class<?> clazz)
Resolve the list of
configuration
attributes for the supplied class and its superclasses. |
(package private) static ContextLoader |
resolveContextLoader(java.lang.Class<?> testClass,
java.lang.String defaultContextLoaderClassName)
Resolve the
ContextLoader class to use for the
supplied testClass and then instantiate and return that
ContextLoader . |
(package private) static java.lang.Class<? extends ContextLoader> |
resolveContextLoaderClass(java.lang.Class<?> testClass,
java.lang.String defaultContextLoaderClassName)
|
private static final Log logger
private static final java.lang.String DEFAULT_CONTEXT_LOADER_CLASS_NAME
static ContextLoader resolveContextLoader(java.lang.Class<?> testClass, java.lang.String defaultContextLoaderClassName)
ContextLoader
class
to use for the
supplied testClass
and then instantiate and return that
ContextLoader
.
If the supplied defaultContextLoaderClassName
is
null
or empty, the standard
default context loader class name "org.springframework.test.context.support.DelegatingSmartContextLoader"
will be used. For details on the class resolution process, see
#resolveContextLoaderClass()
.
testClass
- the test class for which the ContextLoader
should be resolved (must not be null
)defaultContextLoaderClassName
- the name of the default
ContextLoader
class to use (may be null
)ContextLoader
for the supplied
testClass
(never null
)#resolveContextLoaderClass()
static java.lang.Class<? extends ContextLoader> resolveContextLoaderClass(java.lang.Class<?> testClass, java.lang.String defaultContextLoaderClassName)
ContextLoader
Class
to use for the supplied
testClass
.
loader
attribute of
@ContextConfiguration
is configured
with an explicit class, that class will be returned.loader
class is not specified, the class hierarchy
will be traversed to find a parent class annotated with
@ContextConfiguration
; go to step #1.loader
class is found after traversing
the class hierarchy, an attempt will be made to load and return the class
with the supplied defaultContextLoaderClassName
.testClass
- the class for which to resolve the ContextLoader
class; must not be null
defaultContextLoaderClassName
- the name of the default
ContextLoader
class to use; must not be null
or emptyContextLoader
class to use for the supplied test classjava.lang.IllegalArgumentException
- if @ContextConfiguration
is not
present on the supplied test classjava.lang.IllegalStateException
- if the default ContextLoader
class
could not be loadedstatic java.util.List<ContextConfigurationAttributes> resolveContextConfigurationAttributes(java.lang.Class<?> clazz)
configuration
attributes
for the supplied class
and its superclasses.
Note that the inheritLocations
flag of @ContextConfiguration
will be taken into consideration.
Specifically, if the inheritLocations
flag is set to
true
, configuration attributes defined in the annotated
class will be appended to the configuration attributes defined in
superclasses.
clazz
- the class for which to resolve the configuration attributes (must
not be null
)null
)java.lang.IllegalArgumentException
- if the supplied class is null
or
if @ContextConfiguration
is not present on the supplied classstatic java.lang.String[] resolveActiveProfiles(java.lang.Class<?> clazz)
Class
.
Note that the inheritProfiles
flag of @ActiveProfiles
will be taken into
consideration. Specifically, if the inheritProfiles
flag is
set to true
, profiles defined in the annotated class will be
merged with those defined in superclasses.
clazz
- the class for which to resolve the active profiles (must
not be null
)null
)ActiveProfiles
,
Profile
static MergedContextConfiguration buildMergedContextConfiguration(java.lang.Class<?> testClass, java.lang.String defaultContextLoaderClassName)
merged context configuration
for the supplied testClass
and
defaultContextLoaderClassName
.testClass
- the test class for which the MergedContextConfiguration
should be built (must not be null
)defaultContextLoaderClassName
- the name of the default
ContextLoader
class to use (may be null
)#resolveContextLoader()
,
#resolveContextConfigurationAttributes()
,
SmartContextLoader#processContextConfiguration()
,
ContextLoader#processLocations()
,
#resolveActiveProfiles()
,
MergedContextConfiguration